﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace NuMvvm.Commands
{
    public static class CommandExtensions
    {
        public static void RaiseCanExecuteChanged(this ICommand command)
        {
            if (command == null)
                throw new ArgumentNullException("command");

            var method = command.GetType().GetRuntimeMethod("RaiseCanExecuteChanged", new Type[] { });
            if(method != null)
            {
                method.Invoke(command, null);
            }
            else
            {
                throw new InvalidOperationException();
            }
        }

        public static void Execute(this ICommand command)
        {
            command.Execute();
        }

        public static bool CanExecute(this ICommand command)
        {
            return command.CanExecute();
        }
    }
}
